package com.cardone.platform.common.action;

import com.cardone.common.cache.util.CacheUtils;
import com.cardone.common.util.StringUtils;
import com.cardone.context.ContextHolder;
import com.cardone.context.action.Run1Action;
import com.cardone.platform.common.service.EntityLogService;
import com.cardone.security.token.util.TokenUtils;
import org.apache.commons.collections.MapUtils;

import java.util.Map;

/**
 * Created by c100000002 on 15-2-6.
 */
public class TokenRemoveAction implements Run1Action<Map<String, Object>> {
    @Override
    public void run(Map<String, Object> stringObjectMap) {
        String clientId = MapUtils.getString(stringObjectMap, "client_id");
        String oldTokenKey = MapUtils.getString(stringObjectMap, "old_token_key");

        ContextHolder.getBean(EntityLogService.class).updateByClient(clientId, oldTokenKey, "deleted");

        if (StringUtils.isNotBlank(oldTokenKey)) {
            CacheUtils.evict(TokenUtils.class.getName(), oldTokenKey);
        }

        CacheUtils.clear(clientId);
    }
}
